//
//  JQFYChatGroupCell.m
//  JQFY
//
//  Created by 代辉 on 2017/8/23.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYChatGroupCell.h"
#import "UIImage+JQFYCornerRandius.h"

@interface JQFYChatGroupCell ()

@property (nonatomic,strong) UIImageView *groupIcon;            // 群聊头像
@property (nonatomic,strong) UILabel *groupName;                // 群聊名字
@property (nonatomic,strong) UILabel *night;
@property (nonatomic,strong) UILabel *groupNum;                 // 人数
@property (nonatomic,strong) UILabel *chatManger;               // 群主
@property (nonatomic,strong) UIButton *chatButton;
@end

@implementation JQFYChatGroupCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.textLabel.textColor = [UIColor whiteColor];
        [self setupUI];
    }
    
    return self;
}

/**
 头像
 */
- (UIImageView *)groupIcon
{
    if (_groupIcon == nil) {

        UIImage *image = [[UIImage imageNamed:@"group_iconImg"] imageWithCornerRadius:28];

        _groupIcon = [[UIImageView alloc] initWithImage:image];
        _groupIcon.layer.cornerRadius = 57 *0.5 *SCAL;
        _groupIcon.layer.masksToBounds = YES;
    }
    return _groupIcon;
}

/**
 名字
 */
- (UILabel *)groupName
{
    if (_groupName == nil) {
        _groupName = [UILabel new];
        _groupName.font = [UIFont fontWithName:@"Georgia-Bold" size:17];
        _groupName.textColor = [UIColor colorWithHex:0x9053EB];
        _groupName.text = @"UNINHIBTED";
    }
    return _groupName;
}

/**
 人数
 */
- (UILabel *)groupNum
{
    if (_groupNum == nil) {
        _groupNum = [UILabel new];
        _groupNum.font = [UIFont systemFontOfSize:9];
        _groupNum.textColor = [UIColor lightGrayColor];
        _groupNum.text = @"200";
    }
    return _groupNum;
}

/**
 chat
 */
- (UIButton *)chatButton
{
    if (_chatButton == nil) {
        _chatButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_chatButton setBackgroundImage:[UIImage imageNamed:@"group_joinBtn"] forState:UIControlStateNormal];
        [_chatButton setImage:[UIImage imageNamed:@"chat"] forState:UIControlStateNormal];
    }
    return _chatButton;
}


/**
 群主
 */
- (UILabel *)chatManger
{
    if (_chatManger == nil) {
        _chatManger = [UILabel new];
        _chatManger.font = [UIFont fontWithName:@"Georgia-Bold" size:9];
        _chatManger.text = @"UNINHIBTED";
    }
    return _chatManger;
}
- (void)setupUI
{
    UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"group_bg"]];
    [self.contentView addSubview:bgImageView];
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.contentView addSubview:self.groupIcon];
    [self.groupIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(14 *SCAL);
        make.left.equalTo(self.contentView).offset(30 *SCAL);
        make.width.height.mas_equalTo(57 *SCAL);
    }];
    
    [self.contentView addSubview:self.groupName];
    [self.groupName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.groupIcon).offset(4 *SCAL);
        make.left.equalTo(self.groupIcon.mas_right).offset(18 *SCAL);
        make.width.mas_equalTo(180 *SCAL);
    }];
    
    UILabel *night = [[UILabel alloc] init];
    night.text = @"2017UNINHIBITED NIGHT";
    night.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:night];
    [night mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.groupName);
        make.top.equalTo(self.groupName.mas_bottom);
        make.width.mas_equalTo(180 *SCAL);
    }];
    self.night = night;
    
    UIImageView *p = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"p（合并）"]];
    [self.contentView addSubview:p];
    [p mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.groupName);
        make.top.equalTo(night.mas_bottom).offset(5 *SCAL);
    }];
    
    [self.contentView addSubview:self.groupNum];
    [self.groupNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(p);
        make.left.equalTo(p.mas_right).offset(4 *SCAL);
    }];
    
    UIImageView *zhu = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"主（合并）"]];
    [self.contentView addSubview:zhu];
    [zhu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_groupNum.mas_right).offset(20 *SCAL);
        make.centerY.equalTo(self.groupNum);
    }];
    
    [self.contentView addSubview:self.chatManger];
    [self.chatManger mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(zhu.mas_right).offset(5 *SCAL);
        make.centerY.equalTo(zhu);
    }];
    
    [self.contentView addSubview:self.chatButton];
    [self.chatButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.groupName.mas_centerY);
        make.right.equalTo(self.contentView).offset(-25 *SCAL);
    }];
    
    [self.chatButton addTarget:self action:@selector(chatButtonAction) forControlEvents:UIControlEventTouchUpInside];
}
- (void)setGroupInfo:(JQFYUserJoinInChatGroupModel *)groupInfo
{
    /*
     "group_count":群人数,
     "group_name":"群名称",
     "group_owner_user":"群主环信ID",
     "group_head_path":"群头像",
     "group_introduce":"群简介",
     "group_easemob_id":"群环信ID"
     */
    _groupInfo = groupInfo;
    [self.groupIcon sd_setImageWithURL:[NSURL URLWithString:groupInfo.group_head_path] placeholderImage:[UIImage imageNamed:@"group_iconImg"]];
    self.groupNum.text = groupInfo.group_count;
    self.groupName.text = groupInfo.group_name;
    self.night.text = groupInfo.group_introduce;
    
}
#pragma mark - chatAction -
- (void)chatButtonAction
{
    NSLog(@"chat被点击了");
}
@end
